package com.example.androidcomplete0102.ch12;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemSelectedListener;
import android.widget.ArrayAdapter;
import android.widget.Spinner;
import android.widget.Toast;

import com.example.androidcomplete0102.R;

public class SpinnerEx extends Activity {
	ArrayAdapter<CharSequence> adapter;
	boolean mInitSpinner;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.ch12_spinnerex);
		
		Spinner spin =(Spinner)findViewById(R.id.ch12_spinnerex_myspinner);
		spin.setPrompt("과일을 고르세요");
		
		adapter = ArrayAdapter.createFromResource(this, R.array.fruits, android.R.layout.simple_spinner_item);
		adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
		
		spin.setAdapter(adapter);
		
		spin.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {

			@Override
			public void onItemSelected(AdapterView<?> parent, View view,
					int position, long id) {
				if(!mInitSpinner){
					mInitSpinner = true;
					return;
				}
				
				Toast.makeText(getApplicationContext(), adapter.getItem(position)+"는 맛있다.", Toast.LENGTH_SHORT).show();
				
			}

			@Override
			public void onNothingSelected(AdapterView<?> parent) {
				
			}
		});
	}
	
	
}
